package com.gxy.learn.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxy.learn.dao.OrderMapper;
import com.gxy.learn.entity.Order;
import com.gxy.learn.feign.ProviderClient;
import com.gxy.learn.service.OrderService;
import io.seata.core.context.RootContext;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Random;

@Slf4j
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Autowired
    private ProviderClient providerClient;

    @Override
//    @GlobalTransactional(name = "my_test_tx_group",rollbackFor = Exception.class)
    @GlobalTransactional
    public void testCreatOrder() {
        log.info("xid = {}", RootContext.getXID());
        baseMapper.insert(new Order(Long.valueOf(new Random().nextInt(100)),"测试订单",11,"order@126.com"));
        providerClient.insert();
        int num = 1/0;
    }
}
